# 场景：使用Akshare生成股票收益率报告和可视化图表

import akshare as ak
import pandas as pd
import matplotlib.pyplot as plt

# 获取股票日线行情数据
stock_data = ak.stock_zh_a_daily(symbol="sz000001", start_date="2022-01-01", end_date="2022-12-31")

# 计算股票收益率
stock_data["return"] = stock_data["close"].pct_change()

# 生成收益率报告
return_report = stock_data["return"].describe()

# 绘制收益率分布图
plt.figure(figsize=(10, 6))
plt.hist(stock_data["return"].dropna(), bins=30, alpha=0.7)
plt.xlabel("Return")
plt.ylabel("Frequency")
plt.title("Stock Return Distribution")
plt.show()

# 打印收益率报告
print(return_report)